
class HomePageUI extends egret.Sprite {

    public constructor() {
        super();
        this.once(egret.Event.ADDED_TO_STAGE, this.createView, this);
    }
    private shpBeMask1;
    private shpBeMask2;
    private shpBeMask3;
    private createView(): void {
        //创建背景
        var bg = createBitmap("bg_jpg");
        this.addChild(bg);
        var snowflake1_1 = createBitmap("one_snowflower_png", 0, 0);
        var snowflake2_2 = createBitmap("one_snowflower_png", 0, -1206);
        egret.Tween.get(snowflake1_1, { loop: true }).to({ y: 1206 }, 10000);
        egret.Tween.get(snowflake2_2, { loop: true }).to({ y: 0 }, 10000);
        this.addChild(snowflake1_1);
        this.addChild(snowflake2_2);

        //标题
        var title = createBitmap("title_png", 17, 112)
        this.addChild(title);

        var flor1 = createBitmap("one_snow_png", 0, 850)
        this.addChild(flor1)
        // //老虎机
        var game_cj = createBitmap("mouth_png", 32, 342)
        egret.Tween.get(game_cj, { loop: true }).to({ y: 342 }, 100).to({ y: 338 }, 100);
        this.addChild(game_cj);

        //领取按钮
        var btn1 = createBitmap("btn_green_png", 180, 1044)
        this.addChild(btn1)
        btn1.anchorOffsetX = btn1.width * .5;
        btn1.anchorOffsetY = btn1.height * .5;
        btn1.x = 180 + btn1.width * .5;
        btn1.y = 1044 + btn1.height * .5;
        var btn = createTextFiled("立即领取_", 300, 1060, 40, 0xffffff);
        this.addChild(btn);
        //
        var shpBe1 = drawReactShape("", 171, 695, 97, 135, "");
        this.addChild(shpBe1);
        this.shpBeMask1 = new egret.DisplayObjectContainer();
        this.shpBeMask1.x = 171;
        this.shpBeMask1.y = 695;
        this.shpBeMask1.width = 97;
        this.shpBeMask1.height = 540;
        this.addChild(this.shpBeMask1);
        var pic1 = createBitmap("vipcard_png", 0, 0);
        var pic2 = createBitmap("flow_png", 0, 135);
        var pic3 = createBitmap("starbucks_png", 0, 270);
        var pic4 = createBitmap("vipcard_png", 0, 405);
        this.shpBeMask1.addChild(pic1);
        this.shpBeMask1.addChild(pic2);
        this.shpBeMask1.addChild(pic3);
        this.shpBeMask1.addChild(pic4);
        this.shpBeMask1.mask = shpBe1;
        var shpBe2 = drawReactShape("", 325, 695, 97, 135, "");
        this.addChild(shpBe2);
        this.shpBeMask2 = new egret.DisplayObjectContainer();
        this.shpBeMask2.x = 325;
        this.shpBeMask2.y = 695;
        this.shpBeMask2.width = 97;
        this.shpBeMask2.height = 540;
        this.addChild(this.shpBeMask2);
        var pic11 = createBitmap("flow_png", 0, 0);
        var pic21 = createBitmap("starbucks_png", 0, 135);
        var pic31 = createBitmap("vipcard_png", 0, 270);
        var pic41 = createBitmap("flow_png", 0, 405);
        this.shpBeMask2.addChild(pic11);
        this.shpBeMask2.addChild(pic21);
        this.shpBeMask2.addChild(pic31);
        this.shpBeMask2.addChild(pic41);
        this.shpBeMask2.mask = shpBe2;
        var shpBe3 = drawReactShape("", 474, 695, 97, 135, "");
        this.addChild(shpBe3);
        this.shpBeMask3 = new egret.DisplayObjectContainer();
        this.shpBeMask3.x = 474;
        this.shpBeMask3.y = 695;
        this.shpBeMask3.width = 97;
        this.shpBeMask3.height = 540;
        this.addChild(this.shpBeMask3);
        var pic12 = createBitmap("starbucks_png", 0, 0);
        var pic22 = createBitmap("vipcard_png", 0, 135);
        var pic32 = createBitmap("flow_png", 0, 270);
        var pic42 = createBitmap("starbucks_png", 0, 405);
        this.shpBeMask3.addChild(pic12);
        this.shpBeMask3.addChild(pic22);
        this.shpBeMask3.addChild(pic32);
        this.shpBeMask3.addChild(pic42);
        this.shpBeMask3.mask = shpBe3;
        //点击按钮
        var laohuji = createBitmap("bizi_03_png", 310, 554)
        this.addChild(laohuji)
        laohuji.touchEnabled = true
        //中奖弹窗

        var winHave = div(0, 0, 750, 0, 750, 1206, 0, 1206, 0, 1206, 0, 0);           //添加容器
        this.addChild(winHave);

        var winHaveBottom = createBitmap("win_noneBottom_png", 0, 775);
        winHave.addChild(winHaveBottom);

        var winHaveBgMsg = createBitmap("win_haveBgMsg_png", 15, 200);
        winHave.addChild(winHaveBgMsg);

        var winHaveBtnpink = createBitmap("win_noneBtnpink_png", 285, 870);
        winHave.addChild(winHaveBtnpink);

        var winHaveMoney = createTextFiled("123456元已飞入您的微信钱包，请注意查收哟！  ", 200, 430, 36, 0x54734a, "center", 345, 157)
        winHaveMoney.bold = true;
        winHaveMoney.lineSpacing = 20;
        winHave.addChild(winHaveMoney);

        var winHaveContinue = createTextFiled("继续游戏", 310, 880, 25, 0xffffff, "center", 154, 50)
        winHaveContinue.bold = true;
        winHaveContinue.lineSpacing = 15;
        winHaveContinue.touchEnabled = true;

        winHaveContinue.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
            SenceManage.create(this.stage).loadSence("GameUI", null, GameUI);//跳转场景游戏 [JT02271405]
        }, this)

        winHave.addChild(winHaveContinue);

        var winHavePs = createTextFiled("Ps:", 130, 750, 23, 0xffffff);
        winHavePs.bold = true;
        winHavePs.lineSpacing = 15;
        winHave.addChild(winHavePs);

        var winHaveLq = createTextFiled("已有998人领取了现金豪礼!", 130, 780, 23, 0xffffff)
        winHaveLq.bold = true;
        winHaveLq.lineSpacing = 10;
        winHave.addChild(winHaveLq);
        winHave.visible = false

        //中奖结果有
        //中奖结果页【有卡牌】                               //添加容器背景  
        var win_result = div(0, 0, 750, 0, 750, 1206, 0, 1206, 0, 1206, 0, 0);           //添加容器
        this.addChild(win_result);


        //雪花背景
        var snowBG1 = createBitmap("one_snowflower_png", 0, 0);
        var snowBG2 = createBitmap("one_snowflower_png", 0, -1206);
        win_result.addChild(snowBG1);
        win_result.addChild(snowBG2);
        egret.Tween.get(snowBG1, { loop: true }).to({ y: 1206 }, 10000);
        egret.Tween.get(snowBG2, { loop: true }).to({ y: 0 }, 10000);

        var winningImg = createBitmap("winresultPink_png", 30, 20);             //添加标题粉红背景图
        win_result.addChild(winningImg)

        var win_title = createTextFiled("中  奖  了 ！", 117, 25, 48, 0xffffff, "center", 560, 88, "middle");                                                                  //添加标题
        win_title.bold = true;
        win_result.addChild(win_title);

        var win_bgmsg = createBitmap("winresultBg_png", 20, 147);
        win_result.addChild(win_bgmsg);

        var jpmc = createTextFiled("( 手机流量包 )", 0, 860, 35, 0xffffff, "center", 750, 50, "middle");
        jpmc.bold = true;
        win_result.addChild(jpmc);

        var win_receive = createTextFiled("已被你翻牌，请火速前来领取", 0, 910, 28, 0xffffff, "center", 750, 50, "middle");
        win_receive.bold = true;
        win_result.addChild(win_receive);

        var place = createTextFiled("领取地址：", 120, 1020, 28, 0xffffff, "left");
        win_result.addChild(place);

        var ad = createTextFiled("广州海珠区新港东路中洲交易中心8888号2999室", 260, 1020, 28, 0xffffff, "left", 380);
        ad.lineSpacing = 10;
        win_result.addChild(ad);

        var receive_methed = createTextFiled("领取方式：", 120, 1100, 28, 0xffffff, "left");
        win_result.addChild(receive_methed);

        var time = createTextFiled("2016年06月15日-2017年04月30日到现场领取", 260, 1100, 28, 0xffffff, "left", 380);
        time.lineSpacing = 10;
        win_result.addChild(time);
        win_result.visible = false

        //中奖奖品图片
        //没有中奖的页面

        var win_none = div(0, 0, 750, 0, 750, 1206, 0, 1206, 0, 1206, 0, 0);           //添加容器
        this.addChild(win_none);

        var win_noneBottom = createBitmap("win_noneBottom_png", 0, 775);
        win_none.addChild(win_noneBottom);

        var win_noneBgMsg = createBitmap("win_noneBgMsg_png", 15, 200);
        win_none.addChild(win_noneBgMsg);

        var win_noneBtnpink = createBitmap("win_noneBtnpink_png", 285, 870);
        win_none.addChild(win_noneBtnpink);

        var win_noneNoReceive = createTextFiled("还没领取到现金豪礼", 240, 350, 36, 0x54734a, "center", 280, 127)
        win_noneNoReceive.bold = true;
        win_noneNoReceive.lineSpacing = 15;
        win_none.addChild(win_noneNoReceive);

        var win_noneReason = createTextFiled("原因：分享出去后链接没被打开， 快去让好友打开链接试试！", 230, 480, 20, 0x000000, "left", 310, 90)
        win_noneReason.bold = true;
        win_noneReason.lineSpacing = 10;
        win_none.addChild(win_noneReason);

        var win_noneContinue;
        win_noneContinue = createTextFiled("继续游戏", 310, 880, 25, 0xffffff, "center", 154, 50);
        win_noneContinue.bold = true;
        win_noneContinue.lineSpacing = 15;
        win_noneContinue.touchEnabled = true;
        win_noneContinue.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {//按钮点击事件
            SenceManage.create(this.stage).loadSence("win_none", null, GameUI);//跳转场景游戏 [JT02271405]
                        // egret.Tween.get(this).to({x:-640},500);
        });
        win_none.addChild(win_noneContinue);

        var win_nonePs = createTextFiled("Ps:", 130, 750, 23, 0x000000)
        win_nonePs.bold = true;
        win_nonePs.lineSpacing = 10;
        win_none.addChild(win_nonePs);

        var win_noneLq = createTextFiled("已有998人领取了现金豪礼!", 130, 780, 23, 0x000000)
        win_noneLq.bold = true;
        win_noneLq.lineSpacing = 10;
        win_none.addChild(win_noneLq);
        win_none.visible = false;

        //立即领取按钮
        var onoff = true;
        laohuji.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
            if (onoff) {
                onoff = false;
                var x1 = 2, x2 = 3, x3 = 1;//奖品1
                if (x1 == 3 && x2 == 1 && x3 == 2) {
                    //1号奖
                    btn.touchEnabled = true
                    btn.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
                        // this.alpha = 0;
                        title.visible = false;
                        // win_title.visible = false;
                        var prize = createBitmap("starbucks_png", 250, 470);
                        prize.scaleX = 2;
                        prize.scaleY = 2;
                        win_result.addChild(prize);
                        egret.Tween.get(prize, { loop: true }).to({ scaleX: 2, scaleY: 2 }, 1000).to({ scaleX: 1, scaleY: 1 }, 1000).to({ scaleX: 2, scaleY: 2 }, 1000);
                        win_result.visible = true
                        win_result.touchEnabled = true
                        win_result.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
                        }, this)
                    }, this)
                } else if (x1 == 1 && x2 == 2 && x3 == 3) {
                    //现金奖
                    btn.touchEnabled = true
                    btn.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
                        title.visible = false;
                        winHave.visible = true
                        winHave.touchEnabled = true
                        winHave.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
                            winHave.visible = false
                        }, this)
                    }, this)
                } else if (x1 == 2 && x2 == 3 && x3 == 1) {
                    //3号奖
                    btn.touchEnabled = true
                    btn.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
                        title.visible = false;
                        var prize = createBitmap("flow_png", 380, 640)
                        prize.anchorOffsetX = prize.width * .5;
                        prize.anchorOffsetY = prize.height * .5;
                        prize.scaleX = 2;
                        prize.scaleY = 2;
                        win_result.addChild(prize);
                        egret.Tween.get(prize, { loop: true }).to({ scaleX: 2, scaleY: 2 }, 1000).to({ scaleX: 2.5, scaleY: 2.5 }, 1000).to({ scaleX: 2, scaleY: 2 }, 1000);
                        win_result.visible = true
                        win_result.touchEnabled = true
                        win_result.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
                        }, this)
                    }, this)
                } else {
                    //没中奖
                    btn.touchEnabled = true
                    btn.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
                        win_none.visible = true
                    }, this)
                }
                this.Mask(this.shpBeMask1, 500, 0, 5, x1);
                this.Mask(this.shpBeMask2, 500, 0, 8, x2);
                this.Mask(this.shpBeMask3, 500, 0, 10, x3);
            }
        }, this)
        egret.Tween.get(btn1, { loop: true }).to({ scaleX: 1.2, scaleY: 1.2 }, 1000).to({ scaleX: 1, scaleY: 1 }, 1000)
    }
    //老虎机抽奖
    private Mask(mask, time, j, num, x) {

        egret.Tween.get(mask).to({ y: 290 }, time).call(function () {
            mask.y = 695;
            j++;
            console.log(j, time);

            if (j < num) {
                time *= .9;
                time < 30 ? time = 30 : time = time;
            } else {
                time *= 1.1;
                time > 1000 ? time = 1000 : time = time;
            }
            if (time >= 1000) {
                egret.Tween.pauseTweens(mask);
                egret.Tween.get(mask).to({ y: (x * 135 + 290) }, 1300);
            } else {
                this.Mask(mask, time, j, num, x);
            }
        }.bind(this));
    }


}
